package com.joysuch.wwyt.dzhapi.result;

import com.joysuch.wwyt.core.enums.Status;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @program: backend-framework
 * @Description: Api接口异常对象
 * @author: JamesZY
 **/
@Data
@NoArgsConstructor
public class ApiResult implements Serializable {

    /**
     * 返回码
     */
    private int code;
    /**
     * 状态
     */
    private String status;
    /**
     * 返回信息
     */
    private String errMsg;
    /**
     * 返回数据
     */
    private Object data;

    public static ApiResult success() {
        return new ApiResult(Status.SUCCESS.getCode(), Status.SUCCESS_STATUS, null);
    }

    public static ApiResult successData(Object data) {
        return new ApiResult(Status.SUCCESS.getCode(), Status.SUCCESS_STATUS, data);
    }

    public static ApiResult error() {
        return new ApiResult(Status.FAILED.getCode(), Status.ERROR_STATUS, null);
    }

    public static ApiResult error(String msg) {
        return new ApiResult(Status.FAILED.getCode(), Status.ERROR_STATUS, msg, null);
    }

    public static ApiResult error(int code, String msg) {
        return new ApiResult(code, Status.ERROR_STATUS, msg, null);
    }

    public static ApiResult success(Object data) {
        return new ApiResult(Status.SUCCESS.getCode(), Status.SUCCESS_STATUS, data);
    }

    public ApiResult(int code, String status, Object data) {
        this.code = code;
        this.status = status;
        this.data = data;
    }

    public ApiResult(int code, String status, String errMsg, Object data) {
        this.code = code;
        this.status = status;
        this.errMsg = errMsg;
        this.data = data;
    }
}
